package gui.event;

import gui.GameConstants;
import gui.drawers.HoverDrawer;

import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

import javax.swing.JLayeredPane;
import javax.swing.JList;

import dal.object.MapObject;

public class HexGridMotionListener implements MouseMotionListener {
	private HexGrid hg;
	private JList typeList;
	private JLayeredPane jLayers;
	private HexGridListener listener;
	
	public HexGridMotionListener(HexGrid hg, JLayeredPane jLayers, JList typeList){
		this.hg = hg;
		this.typeList = typeList;
		this.jLayers = jLayers;
	}
	
	public void setMouseListener(HexGridListener listener){
		this.listener = listener;
	}
	
	/**
	 * Hover
	 */
	public void mouseMoved(MouseEvent mouse){
		Object selected = typeList.getSelectedValue();
		
		if(selected != null){
			int i = hg.convertToIndex(mouse.getX(), mouse.getY());
			((HoverDrawer) jLayers.getComponentsInLayer(GameConstants.HOVER_LAYER)[0]).drawHover(
					hg.getHorizontalIndex(), hg.getVerticalIndex(), (MapObject) selected, i >= 0);
		}
	}

	/**
	 * The same as mousePressed.
	 */
	public void mouseDragged(MouseEvent mouse) {
		if(listener != null){ 
			listener.updateMap(hg.convertToIndex(mouse.getX(), mouse.getY()), 
					mouse.getModifiersEx() == MouseEvent.BUTTON1_DOWN_MASK);
		}
	}
}
